package org.tinygroup.metadatadictloader;

import org.tinygroup.dict.Dict;
import org.tinygroup.dict.DictGroup;
import org.tinygroup.dict.DictItem;
import org.tinygroup.dict.DictManager;
import org.tinygroup.dict.impl.AbstractDictLoader;
import org.tinygroup.metadata.dict.DictProcessor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by wangwy11342 on 2017/5/19.
 */
public class MetadataDictLoaderImpl extends AbstractDictLoader{
    private DictProcessor dictProcessor;

    public void setDictProcessor(DictProcessor dictProcessor) {
        this.dictProcessor = dictProcessor;
    }

    public void load(DictManager dictManager) {
        Map<String,org.tinygroup.metadata.config.dict.Dict> dictConfigMap = dictProcessor.getDictMap();
        for(String dictKey:dictConfigMap.keySet()){
            org.tinygroup.metadata.config.dict.Dict configDict = dictConfigMap.get(dictKey);
            Dict dict = new Dict();
            dict.setName(configDict.getName());
            dict.setDescription(configDict.getDescription());
            DictGroup dictGroup = new DictGroup();
            dict.addDictGroup(dictGroup);
            for(org.tinygroup.metadata.config.dict.DictItem configDictItem : configDict.getDictItemsList()){
                DictItem dictItem = new DictItem();
                dictItem.setText(configDictItem.getText());
                dictItem.setValue(configDictItem.getValue());
                dictGroup.addDictItem(dictItem);
            }
            dict.addDictGroup(dictGroup);
            putDict(dictKey,dict,dictManager);

        }
    }
}
